package td.pt.event;

import td.domain.Thought;

import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.event.shared.HasHandlers;

public class UseReferenceNavigationEvent extends
		GwtEvent<UseReferenceNavigationEvent.UseReferenceNavigationHandler> {

	public enum ReferenceNavigationType {
		VIEW_REFERENCED_BY_THOUGHT, VIEW_REFERENCES_OF_THOUGHT, ADD_REFERENCE_TO_THOUGHT;
	}

	public static Type<UseReferenceNavigationHandler> TYPE = new Type<UseReferenceNavigationHandler>();
	private Thought thought;
	private HasHandlers source;
	private ReferenceNavigationType referenceNavigationType;

	public interface UseReferenceNavigationHandler extends EventHandler {
		void onUseReferenceNavigation(UseReferenceNavigationEvent event);
	}

	public interface UseReferenceNavigationHasHandlers extends HasHandlers {
		HandlerRegistration addUseReferenceNavigationHandler(
				UseReferenceNavigationHandler handler);
	}

	public UseReferenceNavigationEvent(
			ReferenceNavigationType referenceNavigationType, Thought thought,
			HasHandlers source) {
		this.referenceNavigationType = referenceNavigationType;
		this.thought = thought;
		this.source = source;
	}

	public Thought getThought() {
		return thought;
	}

	public HasHandlers getSource() {
		return source;
	}

	public ReferenceNavigationType getReferenceNavigationType() {
		return referenceNavigationType;
	}

	@Override
	protected void dispatch(UseReferenceNavigationHandler handler) {
		handler.onUseReferenceNavigation(this);
	}

	@Override
	public Type<UseReferenceNavigationHandler> getAssociatedType() {
		return TYPE;
	}

	public static Type<UseReferenceNavigationHandler> getType() {
		return TYPE;
	}

	public static void fire(HasHandlers source,
			ReferenceNavigationType referenceNavigationType, Thought thought) {
		source.fireEvent(new UseReferenceNavigationEvent(
				referenceNavigationType, thought, source));
	}
}
